﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Web;

/// <summary>
/// Summary description for contractDAO
/// </summary>
public class ContractDAO
{
    SqlHelp help = new SqlHelp();
    private string columoPosition = string.Empty;
    private string columnType = string.Empty;
    private string contractNoMain = string.Empty;
    private string tdID = string.Empty;

	public ContractDAO()
	{	}

    #region 获取：公司/部门组
    public DataTable getCoDepGroup(string userCode)
    {
        return help.GetDataTable(string.Format(@"select distinct CD.CoDepCode,CD.CoDepName from B_CoDep CD "
            + " join B_UserCoDep UCD on CD.CoDepCode=UCD.CoDepCode and UserCode='{0}' ", userCode));
    }

    #endregion

    #region 获取合同浏览组
    public DataTable getContractGroup(string coDepCode)
    {
        return help.GetDataTable(string.Format("select CGCode,CGName from B_ContractGroup where CGCode in (select CGCode from B_CoDepAndContractGroup where CoDepCode='{0}') order by CGDesc", coDepCode));
    }

    #endregion

    #region 合同浏览之角色组
    public DataTable getContractGroupRolesGroup(string contractGroupCode)
    {
        return help.GetDataTable("select RG.RGCode,RG.RGName from B_RolesGroup RG join B_ContractGroupAndRolesGroup CGRG on RG.RGCode=CGRG.RGCode "
            + "where RG.DeleteFlag<>1 and CGRG.DeleteFlag<>1 and CGRG.CGCode=@contractGroupCode", new SqlParameter[] { new SqlParameter("@contractGroupCode", contractGroupCode) });
    }

    #endregion

    #region 添加合同

    public int AddContract(ContractModel model)
    {
        SqlParameter[] paras = new SqlParameter[]{
            new SqlParameter("@CoCode",model.CoCode),
            new SqlParameter("@ContractNoMain",model.ContractNoMain),
            new SqlParameter("@CoDepCode",model.contractCoDep),
            new SqlParameter("@UserCode",model.UserCode)
        };
        return help.RunProcInt("AddContract", paras);
    }

    #endregion

    #region ContractColumnAddUpdate

    public int ContractColumnAddUpdate(ContractModel model)
    {
        SqlParameter[] prams=new SqlParameter[]{
            new SqlParameter("@ColumnPosition",model.ColumnPosition),
            new SqlParameter("@ColumnValue",model.ColumnValue),
            new SqlParameter("@ContractNoMain",model.ContractNoMain),
            new SqlParameter("@ID",model.ColumnID),
            new SqlParameter("@CoCode",model.CoCode),
            new SqlParameter("@UserCode",model.UserCode),
        };
        return help.RunProcInt("ContractColumnAddUpdate", prams);
    }

    #endregion

    #region ContractHeadBuid

    public DataTable[] ContractHeadBuid(ContractModel model)
    {
        SqlParameter RGCodeParam = new SqlParameter("@CGCode", model.contractGroup);

        SqlParameter[] prams = new SqlParameter[] { 
            new SqlParameter("@CGCode", model.contractGroup),
            new SqlParameter("@UserCode", model.UserCode)
        };
        return help.RunProcGetTables("forHeadBuild", prams);
    }

    #endregion

    #region ContractList

    public DataTable ContractList(ContractModel model)
    {
        DataTable dt = null;
        if (!string.IsNullOrEmpty(model.ContractListProcName) && model.ContractListProcName.Equals("ContractList"))
        {
            dt = help.RunDataTableProc("ContractList", new SqlParameter[] { new SqlParameter("@ContractNoMain", string.IsNullOrEmpty(model.ContractNoMain) ? "" : model.ContractNoMain) });
        }
        else if (!string.IsNullOrEmpty(model.ContractListProcName) && model.ContractListProcName.Equals("ContractListQuery"))
        {
            dt = help.RunDataTableProc("ContractListQuery",
                new SqlParameter[] { 
                    new SqlParameter("@ContractNoMain", string.IsNullOrEmpty(model.ContractNoMain2) ? "" : model.ContractNoMain2),
                    new SqlParameter("@SaleName", string.IsNullOrEmpty(model.SaleName) ? "" : model.SaleName),
                    new SqlParameter("@CustomerName", string.IsNullOrEmpty(model.CustomerName) ? "" : model.CustomerName),
                    new SqlParameter("@SoNo", string.IsNullOrEmpty(model.SoNo) ? "" : model.SoNo)
                });
        }
        else
        {
            dt = help.RunDataTableProc("ContractList", new SqlParameter[] { new SqlParameter("@ContractNoMain", string.IsNullOrEmpty(model.ContractNoMain) ? "" : model.ContractNoMain) });
        }
        return dt;
    }

    public DataTable ContractList(ContractModel model, DataTable dt)
    {
        return help.RunDataTableProc("GetContractList",
                new SqlParameter[] { 
                    new SqlParameter("@Columns",  GetColumns(dt)),
                    new SqlParameter("@Condiction",model.Condiction)
                });
    }

    public string GetColumns(DataTable dt)
    {
        string columns = string.Empty;
        foreach (DataRow row in dt.Rows)
        {
            if (!row["RepeatFlag"].ToString().Equals("1"))
            {
                columns += "," + row["ColumnType"];
            }
        }
        columns = columns.Replace("ContractNoMain", "C.ContractNoMain").Replace("ContractNoCust", "C.ContractNoCust");
        return columns;
    }
    #endregion

    #region 删除合同
    public int ContractDelete(string contractNos)
    {
        return help.RunProcInt("ContractDelete", new SqlParameter[] { new SqlParameter("@ContractNos", contractNos) });
    }
    #endregion

    #region ShowRepeat

    public string GetColumnsToShow(ContractModel model)
    {
        StringBuilder btemp = new StringBuilder();
        DataTable[] dt = help.RunProcGetTables("GetColumnsToShow",
            new SqlParameter[]{ new SqlParameter("@ColumnPosition",model.ColumnPosition),
            new SqlParameter("@CGCode",model.contractGroup),
            new SqlParameter("@UserCode",model.UserCode)});

        if (dt.Length > 2 && dt[0].Rows.Count > 0 && dt[1].Rows.Count > 0)
        {
            string temp = string.Empty;
            string sql = "select {0} {1}ID,UpdateFlagFromScalaDB from {1} SS join M_Contract C on C.ContractNoMain=SS.ContractNoMain where SS.ContractNoMain='{2}' order by {1}ID ";
            foreach (DataRow row in dt[1].Rows)
            {
                temp += row["ColumnType"].ToString() + ",";
            }
            if (temp.Length > 1)
            {
                temp = string.Format(sql, temp, dt[0].Rows[0]["BelongToTableName"].ToString(), model.ContractNoMain);

                DataTable ddtt = help.GetDataTable(temp);

                btemp.Append("<table class=\"contractTable\" id=\"contractTBrepeate\"  border=\"1px\" cellpadding=\"0px\" cellspacing=\"0px\">");
                btemp.Append(contractHeadBuild(dt[1]));
                int tr = 0;
                Random te = new Random();
                model.listNamesDT = dt[2];
                model.columnUserRight = dt[3];

                foreach (DataRow row in ddtt.Rows)
                {
                    tr = te.Next(2000, 30000000);
                    btemp.Append(contractRowBuild(tr, dt[1], row, model));
                }
                Random a = new Random();
                int aa = a.Next(110000, 2000000);
                btemp.Append(contractRowBuild2(aa, dt[1], ddtt, model));
                btemp.Append("</table>");
                btemp.Append(" <input type=\"button\" id=\"dsfsa\" onclick=\"tempShow('fieldsetShowAddRepeat','none')\" class=\"cmdStyle\" value=\"back\" />");

                return btemp.ToString();
            }
        }
        return "";
    }

    public string contractHeadBuild(DataTable dt)
    {
        StringBuilder head = new StringBuilder();
        head.Append("<thead><tr><td style=\"width:35px;\"></td>");
        int n = dt.Rows.Count;
        for (int i = 0; i < n; i++)
        {
            head.Append("<td  class=\"contractTitleSub\" style=\"width:" + dt.Rows[i]["ColumnWidth"].ToString() + "px\">"
                + dt.Rows[i]["ColumnName"].ToString() + "</td>");
        }
        head.Append("</tr></thead>");

        return head.ToString();
    }
    public string contractRowBuild(int tr, DataTable tddt, DataRow contractRow, ContractModel model)
    {
        StringBuilder row = new StringBuilder();
        contractNoMain = model.ContractNoMain;

        int j = 0;
        int tdNum = tddt.Rows.Count;
        row.Append("<tr><td style=\"width:35px;\"></td>");
        for (int i = j; i < tdNum; i++)
        {
            columnType = tddt.Rows[i]["ColumnType"].ToString();
            columoPosition = tddt.Rows[i]["ColumnPosition"].ToString();

            if (tddt.Rows[i]["DataFromScalaFlag"].ToString().Equals("1") && contractRow["UpdateFlagFromScalaDB"].ToString().Equals("1"))
            {
                row.Append(string.Format("<td title=\"{0}(ContractNo: {1})\" oncontextmenu=\"showLog('viewLogDiv','{2}','{1}','{3}');return false;\">{0}</td>",
                    CommonMethod.ShorStr(contractRow[columnType].ToString(), CommonModel.contractStrLenght), 
                    contractNoMain, tddt.Rows[i]["ColumnType"].ToString(), model.CoCode));
            }
            else if (model.columnUserRight.Select(string.Format("ColumnType='{0}' and RightType in (1,2,3)", columnType)).Length == 0)
            {
                row.Append(string.Format("<td title=\"{0}(ContractNo: {1})\" oncontextmenu=\"showLog('viewLogDiv','{2}','{1}','{3}');return false;\">{4}</td>",
                    contractRow[columnType].ToString(), contractNoMain, tddt.Rows[i]["ColumnType"].ToString(), model.CoCode,
                    CommonMethod.ShorStr(contractRow[columnType].ToString(), CommonModel.contractStrLenght)));
            }
            else if (!tddt.Rows[i]["ColumnTimeStyle"].ToString().Equals("0") && tddt.Rows[i]["ColumnTimeStyle"].ToString().Length > 1)
            {
                tdID = "tr" + tr.ToString() + "td" + columoPosition + "txt1";
                row.Append(string.Format("<td title=\"{0}(ContractNo: {1})\" oncontextmenu=\"showLog('viewLogDiv','{2}','{1}','{3}');return false;\">",
                    contractRow[columnType].ToString(), contractNoMain, tddt.Rows[i]["ColumnType"].ToString(), model.CoCode));

                row.Append(string.Format("<input type=\"text\" style=\"cursor: hand\" class=\"txtStyle2\"  id=\"{0}\" name=\"date\" "
                    + " onfocus=\"ContractUpdateForeDate(1,'','{0}','','','','')\" ", tdID));

                row.Append(string.Format(" onblur=\"ContractUpdateForeDate(2,'{0}',this.id,'{1}','{2}','{3}','{4}')\""
                    + "onclick=\"popUpCalendar(this,document.forms[0].{5},'{6}','{5}',2)\" ",
                    columoPosition, contractNoMain,
                    contractRow[(tddt.Rows[i]["BelongToTableName"].ToString() + "ID")].ToString(),
                    model.CoCode, model.UserCode, tdID, tddt.Rows[i]["ColumnTimeStyle"].ToString()));

                row.Append("value=\"" + contractRow[columnType].ToString() + "\" />");
                row.Append("</td>");
            }
            else if (tddt.Rows[i]["DropDownListNameFlag"].ToString().Equals("1"))
            {
                tdID = "tr" + tr.ToString() + "td" + columoPosition + "txt";
                model.ColumnType = columnType;
                row.Append(string.Format("<td title=\"{0}(ContractNo: {1})\" oncontextmenu=\"showLog('viewLogDiv','{1}','{2}','{3}');return false;\">",
                    contractRow[columnType].ToString(), tddt.Rows[i]["ColumnType"].ToString(), contractNoMain, contractNoMain, model.CoCode));
                row.Append(string.Format("<select id=\"{0}2\" class=\"contractListName\" name=\"contractListName\" ", tdID));
                row.Append(string.Format(" onchange=\"showHiddeTd22(this.id,'{0}','{1}','{2}','{3}','{4}')\">",
                    columoPosition, contractNoMain,
                    tddt.Rows[i]["ForRepeatFlag"].ToString().Equals("1") ? contractRow[(tddt.Rows[i]["BelongToTableName"].ToString() + "ID")].ToString() : "",
                    model.CoCode, model.UserCode));
                row.Append(CommonMethod.GetListNames(model, contractRow[columnType].ToString(), tdID + "2"));
                row.Append("    </select></td>");
            }
            else
            {
                tdID = "tr" + tr.ToString() + "td" + columoPosition + "txt";

                row.Append(string.Format("<td title=\"{0}(ContractNo: {2})\" oncontextmenu=\"showLog('viewLogDiv','{1}','{2}','{3}');return false;\">",
                    contractRow[columnType].ToString(), tddt.Rows[i]["ColumnType"].ToString(), contractNoMain, model.CoCode));
                row.Append(string.Format("<input type=\"text\" class=\"txtStyle2\" id=\"{0}1\" value=\"{1}\" onfocus=\"showHiddeTd1('1','{2}','{3}')\" />",
                    tdID, contractRow[columnType].ToString(), tr.ToString(), columoPosition));
                row.Append(string.Format("<input type=\"text\" class=\"txtStyle1\" id=\"{0}2\" value=\"{1}\" ",
                    tdID, contractRow[columnType].ToString()));
                row.Append(string.Format(" onblur=\"showHiddeTd2('2','{0}','{1}','{2}','{3}','{4}','{5}')\" /></td>",
                    tr.ToString(), columoPosition, contractNoMain,
                    contractRow[(tddt.Rows[i]["BelongToTableName"].ToString() + "ID")].ToString(),
                    model.CoCode, model.UserCode));
            }
        }
        row.Append("</tr>");

        return row.ToString();
    }
    public string contractRowBuild2(int tr, DataTable tddt, DataTable dt, ContractModel model)
    {
        StringBuilder row = new StringBuilder();
        string tableNmae = tddt.Rows[0]["BelongToTableName"].ToString();
        string sql = "select isnull(max(" + tableNmae + "ID),0) from " + tableNmae;
        string StrID = (1 + Convert.ToInt16(help.RunSqlReturn(sql))).ToString();
        int j = 0;
        int tdNum = tddt.Rows.Count;
        row.Append("<tr><td style='text-align:center;'><img alt=\"\" id=\"img" + tr.ToString() + model.ColumnPosition + "\" src=\"../Image/repeate.gif\" onclick=\"ShowAddRepeat(this.id,'"
                    + model.ColumnPosition + "','" + model.ContractNoMain + "','" + model.CoCode + "','" + model.UserCode + "','" + model.contractGroup + "')\" /></td>"); ;
        for (int i = j; i < tdNum; i++)
        {
            columoPosition = tddt.Rows[i]["ColumnPosition"].ToString();

            if (model.columnUserRight.Select(string.Format("ColumnType='{0}' and RightType in (1,2,3)", columnType)).Length == 0)
            {
                row.Append(string.Format("<td oncontextmenu=\"showLog('viewLogDiv','{0}','{1}','{2}');return false;\"></td>",
                    tddt.Rows[i]["ColumnType"].ToString(), model.ContractNoMain, model.CoCode));
            }
            else if (!tddt.Rows[i]["ColumnTimeStyle"].ToString().Equals("0")
                  && tddt.Rows[i]["ColumnTimeStyle"].ToString().Length > 1)
            {
                tdID = "tr" + tr.ToString() + "td" + columoPosition + "txt1";
                row.Append(string.Format("<td oncontextmenu=\"showLog('viewLogDiv','{0}','{1}','{2}');return false;\">",
                    tddt.Rows[i]["ColumnType"].ToString(), model.ContractNoMain, model.CoCode));
                
                row.Append(string.Format("<input type=\"text\" style=\"cursor: hand\" class=\"txtStyle2\"  id=\"{0}\" name=\"date\" ",tdID));
                row.Append(string.Format(" onfocus=\"ContractUpdateForeDate(1,'','{0}','','','','')\" ",tdID));
                row.Append(string.Format(" onblur=\"ContractUpdateForeDate(2,'{0}',this.id,'{1}','{2}','{3}','{4}')\"",
                    columoPosition, contractNoMain, StrID, model.CoCode, model.UserCode));
                row.Append(string.Format("onclick=\"popUpCalendar(this,document.forms[0].{0},'{1}','{0}',2)\" value=\"\" /></td>",
                    tdID, tddt.Rows[i]["ColumnTimeStyle"].ToString()));
            }
            else
            {
                tdID = "tr" + tr.ToString() + "td" + columoPosition + "txt";

                row.Append(string.Format("<td style=\"width:{0}px\" ", tddt.Rows[i]["ColumnWidth"].ToString()));
                row.Append(string.Format(" oncontextmenu=\"showLog('viewLogDiv','{0}','{1}','{2}');return false;\">",
                    tddt.Rows[i]["ColumnType"].ToString(), contractNoMain, model.CoCode));
                row.Append(string.Format("<input type=\"text\" class=\"txtStyle2\" id=\"{0}1\" value=\"\" onfocus=\"showHiddeTd1('1','{1}','{2}')\" />",
                    tdID, tr.ToString(), columoPosition));
                row.Append(string.Format("<input type=\"text\" class=\"txtStyle1\" id=\"{0}2\" value=\"\" ", tdID));
                row.Append(string.Format(" onblur=\"showHiddeTd2('2','{0}','{1}','{2}','{3}','{4}','{5}')\" /></td>",
                    tr.ToString(), columoPosition, contractNoMain,
                    tddt.Rows[i][(tddt.Rows[i]["BelongToTableName"].ToString() + "ID")].ToString(),
                    model.CoCode, model.UserCode));
            }
        }
        row.Append("</tr>");

        return row.ToString();
    }

    #endregion

    #region ShowLog

    public string ShowLog(ContractModel model)
    {
        DataTable dt = help.GetDataTable(string.Format("select ColumnType, ContractNoMain, ColumnValue, UserName+'-'+UserFullName+'-'+UserEngName as UserName ,"
            + " convert(datetime,CR.AddDate) date from ColumnRecord CR left join B_User U on CR.AddAuthor=U.UserCode where CR.ColumnType='{0}' and CR.ContractNoMain='{1}'",
            model.ColumnType, model.ContractNoMain));
        if (dt != null && dt.Rows.Count > 0)
        {
            StringBuilder table = new StringBuilder();
            table.Append("<table class=\"contractTable\" id=\"contractTB\"  border=\"1px\" cellpadding=\"0px\" cellspacing=\"0px\"><thead>");
            table.Append("<tr><td style='width:20px;'>No</td><td style='width:300px;'>Value</td><td style='width:150px;'>"
                + "Added/Updated User</td><td style='width:150px;'>Date</td></tr></thead>");
            int i = 1;
            foreach (DataRow row in dt.Rows)
            {
                table.Append("<tr><td>" + i.ToString() + "</td>");
                table.Append("<td>" + row["ColumnValue"] + "</td>");
                table.Append("<td>" + row["UserName"] + "</td>");
                table.Append("<td>" + row["date"] + "</td>");
                table.Append("</tr>");
                i++;
            }
            table.Append("</table>");
            return table.ToString();
        }

        return "Not Log for it!";
    }

    #endregion

    #region Show Files

    public string GetFilesByContract(string path, int deleteFlag)
    {
        StringBuilder files = new StringBuilder();
        string showFlag = deleteFlag > 0 ? "block" : "none";
        string[] temp = path.Split('/');

        try
        {

            DirectoryInfo Dir = new DirectoryInfo(HttpContext.Current.Server.MapPath("~/" + path + "/"));
            if (Dir.GetFiles().Length > 0)
            {
                files.Append("<table border=\"1px\" cellpadding=\"0px\" style=\"table-layout:fixed;\" cellspacing=\"0px\"><thead>");
                files.Append("<td style=\"width: 200px; text-algin:center;\"> ContractNo.(ITT)</td>");
                files.Append("<td style=\"width: 200px; text-algin:center;\">  Type  </td>");
                files.Append("<td style=\"width: 300px; text-algin:center;\"> File Name</td>");
                files.Append("<td style=\"width: 150px; text-algin:left;\"> Download</td>");
                if (deleteFlag > 0)
                {
                    files.Append("<td style=\"width: 80px; text-algin:left;\"> Delete</td></thead>");
                }
                foreach (FileInfo fileName in Dir.GetFiles())
                {
                    files.Append("<tr><td style=\"width: 200px; text-algin:center;\">" + temp[1] + "</td>");
                    files.Append("<td style=\"width: 200px; text-algin:center;\">" + temp[2] + "</td>");
                    files.Append("<td style=\"width: 300px; text-algin:center;\">" + fileName + "</td>");
                    files.Append("<td style=\"width: 150px; text-algin:left;\"><a href='../FilesDownLoad.aspx?filePosition=" + path + "/"
                        + fileName + "'>下载</a></td>");
                    if (deleteFlag > 0)
                    {
                        files.Append("<td style=\"width: 80px; text-algin:left; Cursor:hand; display:"
                            + showFlag + ";\" onclick=\"ContractFileDelete('" + path + "/"
                            + fileName + "'," + deleteFlag + ")\">删除</td></tr>");
                    }
                }
                files.Append("</table>");
            }
        }
        catch
        {
            files.Append("Not Files Found!");
        }

        return files.ToString();
    }

    #endregion

    #region GetContractNo

    public DataTable GetContractNoForUpdate(string condiction)
    {
        DataTable dt = new DataTable();

        dt = help.GetDataTable(" select distinct ContractNoMain from M_Contract where DeleteFlag=0 " + condiction);

        return dt;
    }

    #endregion

    #region 更新数据
    public void ContractUpdate(ContractModel model, int n)
    {
        ContractInfoGetFromOtherDB commDB = new ContractInfoGetFromOtherDB();
        if (n == 1)
        {
            //commDB.TradingUpdate(model, n);
            commDB.OrderSalesCatalogCustomerTrading(model);
        }
        else if (n == 2)
        {
            SqlParameter[] prams = new SqlParameter[] { new SqlParameter("@contractNos", model.contractNos + "'#@'") };
            DataTable[] dt = help.RunProcGetTables("UpdateTradingPlantGetNosManua", prams);

            string temp = string.Empty;
            if (dt != null && dt.Length > 0)
            {
                if (dt[0] != null && dt[0].Rows.Count > 0)
                {
                    foreach (DataRow row in dt[0].Rows)
                    {
                        if (CommonMethod.CheckNUM(row["TradingPO"].ToString()))
                        { temp += string.Format("'{0}',", Convert.ToInt64(row["TradingPO"].ToString().ToString())); }
                        temp += string.Format("'{0}',", row["TradingPO"].ToString());
                    }
                    if (temp.Length > 1)
                    {
                        model.ContractNoForPlantUpdateDT = dt[0];
                        model.contractNos = temp;
                        commDB.PlantUpdate(model, n);
                    }
                }
                if (dt[1] != null && dt[1].Rows.Count > 0)
                {
                    DataTable tr = dt[1].Clone();
                    foreach (DataRow row in dt[1].Rows)
                    {
                        tr.Clear();
                        DataRow tRow = tr.NewRow();
                        tRow["ContractNoMain"] = row["ContractNoMain"];
                        tRow["ContractNoCust"] = row["ContractNoCust"];
                        tRow["TradingPO"] = row["TradingPO"];
                        tr.Rows.Add(tRow);

                        temp = null;
                        if (CommonMethod.CheckNUM(row["TradingPO"].ToString()))
                        { temp += string.Format("'{0}',", Convert.ToInt64(row["TradingPO"])); }
                        temp += string.Format("'{0}',", row["TradingPO"]);
                        if (temp.Length > 1)
                        {
                            model.ContractNoForPlantUpdateDT = tr;
                            model.contractNos = temp;
                            commDB.PlantUpdate(model, n);
                        }
                    }
                }
            }
        }
    }
    #endregion

    #region 合同号规则
    public DataTable[] GetContractNoRegulation()
    {
        return help.RunProcGetTables("GetContractNoRegulation", null);
    }
    public string GetContractNoRegulation(string cnrHead, string cnrFoot)
    {
        return help.RunProcReturn("GetContractNoByRegulation", new SqlParameter[]{
            new SqlParameter("@CNRHead",cnrHead),
            new SqlParameter("@CNRFoot",cnrFoot)});
    }
    public string GetContractNoRegulation2(string cnrSegment, string CNRCoDe)
    {
        string str = string.Empty;
        DataTable dt = help.GetDataTable(string.Format("select * from B_ContractNoRegulation "
            + "where CNRSegment='{0}' and CNRCoDe='{1}'", cnrSegment, CNRCoDe));
        if (dt != null && dt.Rows.Count > 0)
        {
            str = GetContractNoRegulation(dt.Rows[0]["CNRHead"].ToString(), dt.Rows[0]["CNRFoot"].ToString());
        }
        return str;
    }
    #endregion

    #region 高级查询下拉列表绑定
    public DataTable[] GetddlForadAancedQuery()
    {
        return help.RunProcGetTables("GetDllForContractMoreQuery", null);
    }
    #endregion

    #region 根据合同号查询合同所在公司
    public string GetCoDepByContractNo(string contractNo)
    {
        string temp = string.Empty;
        DataTable dt = help.GetDataTable(string.Format("select distinct CoDepName from ContractCoDep_V where ContractNoMain like '%{0}%'", contractNo));
        if (dt != null && dt.Rows.Count > 0)
        {
            int n = (dt.Rows.Count >= 3 ? 3 : dt.Rows.Count);
            for (int i = 0; i < n; i++)
            {
                temp += dt.Rows[i]["CoDepName"].ToString() + "/";
            }
        }
        else { return " Cannot some about it!"; }
        if (temp.Length > 1)
        { temp = temp.Substring(0, temp.Length - 1); }
        return " It would be in as follow Co. : " + temp;
    }
    #endregion
}